package magicloan.auctionpocket.ui.activity;

import android.content.Intent;
import android.os.Handler;
import android.os.Looper;
import android.view.View;
import android.widget.TextView;
import com.utils.module.android.ToastUtil;
import magicloan.auctionpocket.R;
import magicloan.auctionpocket.bean.UserData;
import magicloan.auctionpocket.ui.base.BaseActivity;
import magicloan.auctionpocket.view.dialog.MaterialDialog;

/**
 * Created by hechao on 2018/2/1.
 */
public class SettingActivity extends BaseActivity {

    @Override
    protected int setContentView() {
        return R.layout.ac_setting;
    }

    @Override
    protected void beforeInitView() {

    }

    @Override
    protected void afterInitView() {

        setTitle("设置",null);

        findViewById(R.id.tv_logout).setOnClickListener(this);
        findViewById(R.id.ll_service).setOnClickListener(this);
        findViewById(R.id.ll_aboutus).setOnClickListener(this);

    }

    @Override
    protected void initData() {

    }

    @Override
    protected void initView() {

    }

    @Override
    public void onClick(View v) {
        super.onClick(v);
        Intent intent = null ;
        switch (v.getId()){
            case R.id.ll_service:
                break;
            case R.id.ll_aboutus:
                intent = new Intent(mActivity,AboutUsActivity.class);
                break;
            case R.id.tv_logout:
                showLoanDialog();
                break;
        }
        if ( intent!=null )
            startActivity(intent);
    }

    /**
     * 这是兼容的 AlertDialog
     */
    private void showLoanDialog() {
        final MaterialDialog dialog = MaterialDialog.getMaterialDialog();
        dialog.initDialog(mActivity);
        dialog.showDialog(R.layout.dialog_logout, 270,160,new MaterialDialog.DialogListener() {
            @Override
            public void onNegativeButtonClick() {
                ToastUtil.showToast(mActivity,"Click");
            }

            @Override
            public void onPositiveButtonClick() {
                ToastUtil.showToast(mActivity,"Click");
            }

            @Override
            public void handleContentView(View contentView) {
                ((TextView)contentView.findViewById(R.id.tv)).setText("确定要退出?");
                contentView.findViewById(R.id.tv_logout).setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        UserData.getInstance().clear();
                        new Handler(Looper.getMainLooper()).postDelayed(new Runnable() {
                            @Override
                            public void run() {
                                dialog.dismiss();
                                ToastUtil.showToast(mActivity,"退出成功");
                                mActivity.finish();
                            }
                        }, 800);
                    }
                });
                contentView.findViewById(R.id.tv_nologout).setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        dialog.dismiss();
                    }
                });
            }
        });
    }


}
